package com.xxk.rocket.star.core.annotation.impl;

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere;
import com.xxk.rocket.star.annotation.StargateFromWhere;
import com.xxk.rocket.star.core.annotation.AbsProcessAnnotationConsume;
import com.xxk.rocket.star.core.dto.StargateConsumeBaseDTO;
import com.xxk.rocket.star.core.utils.StringUtils;

import java.lang.reflect.Method;

public class StargateFromWhereProcessAnnotation
        extends AbsProcessAnnotationConsume<StargateConsumeBaseDTO> {

  @Override
  protected void processConsume(StargateConsumeBaseDTO stargateConsumeBaseDTO, Class aClass,
                                Object o,
                                Method method) throws Throwable {
    StargateFromWhere stargateFromWhere = null;
    if (method == null) {
      stargateFromWhere = (StargateFromWhere) aClass.getAnnotation(StargateFromWhere.class);
    } else {
      stargateFromWhere = method.getAnnotation(StargateFromWhere.class);
    }
    if (stargateFromWhere == null || StringUtils.isBlank(stargateFromWhere.value())
            || ConsumeFromWhere.valueOf(stargateFromWhere.value()) == null) {
      return;
    }
    stargateConsumeBaseDTO.setConsumeFromWhere(ConsumeFromWhere.valueOf(stargateFromWhere.value()));
  }
}
